package _24_beiwanglu_pattern.v6_0_better_Packagability;

/**
 * @Description: 多状态的发起人
 * @Auther: 2019/6/9 0:38 by zhang.jy
 */
public class Originator {
    //内部状态
    private String state = "";
    public String getState() {
        return state;
    }
    public void setState(String state) {
        this.state = state;
    }
    //创建一个备忘录
    public IMemento createMemento(){
        return new Memento(this.state);
    }
    //恢复一个备忘录
    public void restoreMemento(IMemento _memento){
        this.setState(((Memento)_memento).getState());
    }
    //内置类
    private class Memento implements IMemento{
        //发起人的内部状态
        private String state = "";
        //构造函数传递参数
        private Memento(String _state){
            this.state = _state;


        }
        private String getState() {
            return state;
        }
        private void setState(String state) {
            this.state = state;
        }
    }
}